package guoanmaker.operator.business.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import guoanmaker.operator.business.modelnobind.LuckDrawAndCoupons;

@Repository
public class OperatorLuckDrawDao {
	@PersistenceContext
	private EntityManager manager;
	
	public List<LuckDrawAndCoupons> queryAllLuckdrawByActivityId(String Id){
		String sql = "SELECT a.id,a.prize_name,a.probability,a.number,a.pic_url,a.time_start,a.time_end,a.max_draw_num,a.drawnum,a.activity_id,a.is_coupons,a.coupons_id,oc.couponsname FROM t_operator_luckdraw a LEFT JOIN t_operator_coupons oc ON a.coupons_id = oc.id WHERE a.activity_id =:id ORDER BY a.weight";
		Query query = manager.createNativeQuery(sql, LuckDrawAndCoupons.class);
		query.setParameter("id", Id);
		List<LuckDrawAndCoupons> enlist = (List<LuckDrawAndCoupons>) query.getResultList();
		return enlist;
	}

}
